﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gmis.IDAL;
using Gmis.DalFactory;
using System.Data;

namespace Gmis.BLL
{

    /// <summary>
    /// NewsFile
    /// </summary>
    public partial class NewsFile
    {
        private readonly INewsFile dal = DataAccess.CreateNewsFile();
        public NewsFile()
        { }
        #region  Method
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Gmis.Model.NewsFile model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Gmis.Model.NewsFile model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string sId)
        {

            return dal.Delete(sId);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string sIdlist)
        {
            return dal.DeleteList(sIdlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Gmis.Model.NewsFile GetModel(string sId)
        {

            return dal.GetModel(sId);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Gmis.Model.NewsFile> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Gmis.Model.NewsFile> DataTableToList(DataTable dt)
        {
            List<Gmis.Model.NewsFile> modelList = new List<Gmis.Model.NewsFile>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Gmis.Model.NewsFile model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Gmis.Model.NewsFile();
                    if (dt.Rows[n]["sId"] != null && dt.Rows[n]["sId"].ToString() != "")
                    {
                        model.sId = dt.Rows[n]["sId"].ToString();
                    }
                    if (dt.Rows[n]["sVillage"] != null && dt.Rows[n]["sVillage"].ToString() != "")
                    {
                        model.sVillage = dt.Rows[n]["sVillage"].ToString();
                    }
                    if (dt.Rows[n]["sType"] != null && dt.Rows[n]["sType"].ToString() != "")
                    {
                        model.sType = dt.Rows[n]["sType"].ToString();
                    }
                    if (dt.Rows[n]["sFileName"] != null && dt.Rows[n]["sFileName"].ToString() != "")
                    {
                        model.sFileName = dt.Rows[n]["sFileName"].ToString();
                    }
                    if (dt.Rows[n]["sFormat"] != null && dt.Rows[n]["sFormat"].ToString() != "")
                    {
                        model.sFormat = dt.Rows[n]["sFormat"].ToString();
                    }
                    if (dt.Rows[n]["sTitle"] != null && dt.Rows[n]["sTitle"].ToString() != "")
                    {
                        model.sTitle = dt.Rows[n]["sTitle"].ToString();
                    }
                    if (dt.Rows[n]["sDescription"] != null && dt.Rows[n]["sDescription"].ToString() != "")
                    {
                        model.sDescription = dt.Rows[n]["sDescription"].ToString();
                    }
                    if (dt.Rows[n]["sAuthor"] != null && dt.Rows[n]["sAuthor"].ToString() != "")
                    {
                        model.sAuthor = dt.Rows[n]["sAuthor"].ToString();
                    }
                    if (dt.Rows[n]["dDate"] != null && dt.Rows[n]["dDate"].ToString() != "")
                    {
                        model.dDate = DateTime.Parse(dt.Rows[n]["dDate"].ToString());
                    }
                    if (dt.Rows[n]["sCreator"] != null && dt.Rows[n]["sCreator"].ToString() != "")
                    {
                        model.sCreator = dt.Rows[n]["sCreator"].ToString();
                    }
                    if (dt.Rows[n]["sSavePath"] != null && dt.Rows[n]["sSavePath"].ToString() != "")
                    {
                        model.sSavePath = dt.Rows[n]["sSavePath"].ToString();
                    }
                    if (dt.Rows[n]["lEnable"] != null && dt.Rows[n]["lEnable"].ToString() != "")
                    {
                        if ((dt.Rows[n]["lEnable"].ToString() == "1") || (dt.Rows[n]["lEnable"].ToString().ToLower() == "true"))
                        {
                            model.lEnable = true;
                        }
                        else
                        {
                            model.lEnable = false;
                        }
                    }
                    if (dt.Rows[n]["sComment"] != null && dt.Rows[n]["sComment"].ToString() != "")
                    {
                        model.sComment = dt.Rows[n]["sComment"].ToString();
                    }
                    if (dt.Rows[n]["dCreate"] != null && dt.Rows[n]["dCreate"].ToString() != "")
                    {
                        model.dCreate = DateTime.Parse(dt.Rows[n]["dCreate"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}
